﻿using System;
using System.IO;
using System.Reflection;
using Microsoft.Office.PowerPoint.STAMP.Core;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using NUnit.Framework;

namespace Microsoft.Office.PowerPoint.STAMP.Test
{
    [TestFixture]
    public class XmlTest
    {
        private Application _app;

        [SetUp]
        public void TestInitialise()
        {
            _app = new Application();

            _app.Presentations.Add(MsoTriState.msoFalse);
            _app.Presentations[1].Slides.Add(1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank);
        }

        [TearDown]
        public void TestCleanup()
        {
            _app.Quit();
            _app = null;
        }

        [Test]
        public void CreateXmlResource()  
        {
            string[] names = new string[] { "jamie", "jim", "chrisA", "chrisK" };

            CaptionItemsList captionItemsList = CaptionItemsList.Empty;
            foreach (var name in names)
            {
                captionItemsList.CaptionItems.Add(new CaptionItem { Name = name });
            }

            string xmlString = UtilXmlToString.SerializeObject(captionItemsList);

            string id = UtilPowerPoint.AddCustomXmlPartToPresentation(_app.Presentations[1], xmlString);
            string outXml = UtilPowerPoint.GetCustomXmlPartToPresentationById(_app.Presentations[1], id);

            CaptionItemsList temp = UtilXmlToString.DeserializeObject<CaptionItemsList>(outXml);

            Assert.AreEqual(xmlString, outXml);

        }
       
        static public string AssemblyDirectory
        {
            get
            {
                string codeBase = Assembly.GetExecutingAssembly().CodeBase;
                UriBuilder uri = new UriBuilder(codeBase);
                string path = Uri.UnescapeDataString(uri.Path);
                return Path.GetDirectoryName(path);
            }
        }
    }
}
